home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / macintosh-c / macc-carbon-demos-nonbinhex.sit / macc-carbon-demos-nonbinhex / chap18-demo-carbon events / Files.h < prev    next >
Text File  |  2001-06-11  |  8KB  |  177 lines

  1. // *******************************************************************************************
  2. // Files.h                                                                  CARBON EVENT MODEL
  3. // *******************************************************************************************
  4. //
  5. // This program demonstrates:
  6. //
  7. // •    File operations associated with:
  8. //
  9. //        •    The user invoking the Open…, Close, Save, Save As…, Revert, and Quit commands of a
  10. //            typical application.
  11. //
  12. //        •    Handling of the required Apple events Open Application, Re-open Application, Open
  13. //            Documents, Print Documents, and Quit Application.
  14. //
  15. // •    File synchronisation.
  16. //
  17. // •    The creation, display, and handling of Open, Save Location, Choose a Folder, Save
  18. //        Changes, Discard Changes, and Review Unsaved dialogs and alerts using the new model
  19. //        introduced with Navigation Services 3.0.
  20. //
  21. // To keep the code not specifically related to files and file-handling to a minimum, an item
  22. // is included in the Demonstration menu which allows the user to simulate "touching" a window
  23. // (that is, modifying the contents of the associated document).  Choosing the first menu item
  24. // in this menu sets the window-touched flag in the window's document structure to true and
  25. // draws the text "WINDOW TOUCHED" in the window in a large font size, this latter so that the
  26. // user can keep track of which windows have been "touched".
  27. //
  28. // This program is also, in part, an extension of the demonstration program Windows2 in that
  29. // it also demonstrates certain file-related Window Manager features introduced with the Mac
  30. // OS 8.5 Window Manager.  These features are:
  31. //
  32. // •    Window proxy icons.
  33. //
  34. // •    Window path pop-up menus.
  35. //
  36. // Those sections of the source code relating to these features are identified with ///// at
  37. // the right of each line.
  38. //
  39. // The program utilises the following resources:
  40. //
  41. // •    A 'plst' resource containing an information property list which provides information
  42. //        to the Mac OS X Finder.
  43. //
  44. // •    An 'MBAR' resource, and 'MENU' and 'xmnu' resources for Apple, File, Edit and 
  45. //        Demonstration menus (preload, non-purgeable).  
  46. //
  47. // •    A 'STR ' resource containing the "missing application name" string, which is copied to
  48. //        all document files created by the program.
  49. //
  50. // •    'STR#' resources (purgeable) containing error strings, the application's name (for
  51. //        certain Navigation Services functions), and a message    string for the Choose a Folder
  52. //        dialog.
  53. //          
  54. // •    An 'open' resource (purgeable) containing the file type list for the Open dialog.
  55. //
  56. // •    A 'kind' resource (purgeable) describing file types, which is used by Navigation 
  57. //        Services to    build the native file types section of the Show pop-up menu in the Open
  58. //        dialog.
  59. //
  60. // •    Two 'pnot' resources (purgeable) which, together with an associated 'PICT' resource 
  61. //        (purgeable) and a 'TEXT' resource created by the program, provide the previews for
  62. //        the PICT and, on Mac OS 8/9, TEXT files.
  63. //
  64. // •    The 'BNDL' resource (non-purgeable), 'FREF' resources (non-purgeable), signature
  65. //        resource (non-purgeable), and icon family resources (purgeable), required to support the
  66. //        built application on Mac OS 8/9.
  67. //
  68. // •    A 'SIZE' resource with the acceptSuspendResumeEvents, canBackground, 
  69. //        doesActivateOnFGSwitch, and isHighLevelEventAware flags set.
  70. //
  71. // *******************************************************************************************
  72.  
  73. // ………………………………………………………………………………………………………………………………………………………………………………………………………………………… includes
  74.  
  75. #include <Carbon.h>
  76.  
  77. // …………………………………………………………………………………………………………………………………………………………………………………………………………………………… defines
  78.  
  79. #define rMenubar                                    128
  80. #define mAppleApplication                    128
  81. #define  Apple_About                            'abou'
  82. #define mFile                                            129
  83. #define  File_New                                    'new '
  84. #define  File_Open                                'open'
  85. #define  File_Close                                'clos'
  86. #define  File_Save                                'save'
  87. #define  File_SaveAs                            'sava'
  88. #define  File_Revert                            'reve'
  89. #define  File_Quit                                'quit'
  90. #define  iQuit                                        12
  91. #define mDemonstration                        131
  92. #define  Demo_TouchWindow                    'touc'
  93. #define  Demo_ChooseAFolderDialog    'choo'
  94. #define rErrorStrings                            128    
  95. #define  eInstallHandler                    1000
  96. #define  eMaxWindows                            1001
  97. #define  eCantFindFinderProcess        1002                                                                                                     /////
  98. #define rMiscStrings                            129
  99. #define  sApplicationName                    1
  100. #define  sChooseAFolder                        2
  101. #define rOpenResource                            128
  102. #define kMaxWindows                                10
  103. #define kFileCreator                            'Kjbb'
  104. #define kFileTypeTEXT                            'TEXT'
  105. #define kFileTypePICT                            'PICT'
  106. #define kOpen                                            0
  107. #define kPrint                                        1
  108. #define MIN(a,b)                                     ((a) < (b) ? (a) : (b))
  109.  
  110. // ………………………………………………………………………………………………………………………………………………………………………………………………………………………… typedefs
  111.  
  112. typedef struct
  113. {
  114.     TEHandle            editStrucHdl;
  115.     PicHandle            pictureHdl;
  116.     SInt16                fileRefNum;
  117.     FSSpec                fileFSSpec;
  118.     AliasHandle        aliasHdl;
  119.     Boolean                windowTouched;
  120.     NavDialogRef    modalToWindowNavDialogRef;
  121.     NavEventUPP        askSaveDiscardEventFunctionUPP;
  122.     Boolean                isAskSaveChangesDialog;
  123. }    docStructure, *docStructurePointer, **docStructureHandle;
  124.  
  125. // …………………………………………………………………………………………………………………………………………………………………………………………… function prototypes
  126.  
  127. void            main                                                    (void);
  128. void            eventLoop                                            (void);
  129. void            doPreliminaries                                (void);
  130. void            doInstallAEHandlers                        (void);
  131. OSStatus    appEventHandler                                (EventHandlerCallRef,EventRef,void *);
  132. OSStatus    windowEventHandler                        (EventHandlerCallRef,EventRef,void *);
  133. void            doIdle                                                (void);
  134. void            doDrawContent                                    (WindowRef);
  135. void          doMenuChoice                                    (MenuCommand);
  136. void            doAdjustMenus                                    (void);
  137. void            doErrorAlert                                    (SInt16);
  138. void          doCopyPString                                    (Str255,Str255);
  139. void            doConcatPStrings                            (Str255,Str255);
  140. void            doTouchWindow                                    (void);
  141. OSErr            openAppEventHandler                        (AppleEvent *,AppleEvent *,SInt32);
  142. OSErr            reopenAppEventHandler                    (AppleEvent *,AppleEvent *,SInt32);
  143. OSErr            openAndPrintDocsEventHandler    (AppleEvent *,AppleEvent *,SInt32);
  144. OSErr            quitAppEventHandler                        (AppleEvent *,AppleEvent *,SInt32);
  145. OSErr            doHasGotRequiredParams                (AppleEvent *);
  146. SInt16        doReviewChangesAlert                    (SInt16);
  147.  
  148. OSErr            doNewCommand                                    (void);
  149. OSErr            doOpenCommand                                    (void);
  150. OSErr            doCloseCommand                                (NavAskSaveChangesAction);
  151. OSErr            doSaveCommand                                    (void);
  152. OSErr            doSaveAsCommand                                (void);
  153. OSErr            doRevertCommand                                (void);
  154.  
  155. OSErr            doNewDocWindow                                (Boolean,OSType,WindowRef *);
  156. EventHandlerUPP    doGetHandlerUPP                    (void);
  157. OSErr            doCloseDocWindow                            (WindowRef);
  158. OSErr            doOpenFile                                        (FSSpec,OSType);
  159. OSErr            doReadTextFile                                (WindowRef);
  160. OSErr            doReadPictFile                                (WindowRef);
  161. OSErr            doCreateAskSaveChangesDialog    (WindowRef,docStructureHandle,NavAskSaveChangesAction);
  162. OSErr         doSaveUsingFSSpec                            (WindowRef,NavReplyRecord *);
  163. OSErr            doSaveUsingFSRef                            (WindowRef,NavReplyRecord *);
  164. OSErr            doWriteFile                                        (WindowRef);
  165. OSErr            doWriteTextData                                (WindowRef,SInt16);
  166. OSErr            doWritePictData                                (WindowRef,SInt16);
  167.  
  168. void    getFilePutFileEventFunction        (NavEventCallbackMessage,NavCBRecPtr,NavCallBackUserData);
  169. void  askSaveDiscardEventFunction        (NavEventCallbackMessage,NavCBRecPtr,NavCallBackUserData);
  170.  
  171. OSErr            doCopyResources                                (WindowRef);
  172. OSErr            doCopyAResource                                (ResType,SInt16,SInt16,SInt16);
  173.  
  174. void            doSynchroniseFiles                        (void);
  175. OSErr            doChooseAFolderDialog                    (void);
  176.  
  177. // *******************************************************************************************